package com.jhgk.jhcee.system.controller;

import com.jhgk.jhcee.common.domain.UserModel;
import com.jhgk.jhcee.common.resultful.BasisResultful;
import com.jhgk.jhcee.system.domain.model.SysUserInfoModel;
import com.jhgk.jhcee.system.domain.model.SysUserLoginParam;
import com.jhgk.jhcee.system.service.SysUserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;

/**
 * @author: xiezhongping
 * @description:
 * @date: 2021/8/25 9:50.
 */
@RestController
@RequestMapping("/admin")
@Api(value = "管理用户信息", tags = {"管理用户信息"})
public class SysAdminController {

    @Resource(name = "SysUserInfoServiceImpl")
    private SysUserInfoService sysUserInfoService;

    @GetMapping("/getInfo")
    @ApiOperation("获取当前用户信息")
    public BasisResultful<Object> getInfo() {
        return sysUserInfoService.getInfo();
    }

    @GetMapping("/loadUserByUsername")
    @ApiOperation("获取用户基础信息")
    public BasisResultful<UserModel> loadUserByUsername(@RequestParam("username") @NotBlank(message = "用户名不能为空") String username) {
        return sysUserInfoService.loadUserByUsername(username);
    }

    @PostMapping("/login")
    @ApiOperation("用户登录")
    public BasisResultful<Object> login(@RequestBody @Validated SysUserLoginParam sysUserLoginParam) {
        return sysUserInfoService.login(sysUserLoginParam);
    }

    @PostMapping("/userList")
    @ApiOperation("用户列表")
    public BasisResultful<Object> userList(@RequestBody SysUserInfoModel model) {
        return sysUserInfoService.userList(model);
    }

    @PostMapping("/isAccountExist")
    @ApiOperation("账户是否存在")
    public BasisResultful<Object> isAccountExist(@RequestBody @Validated SysUserInfoModel model) {
        return sysUserInfoService.isAccountExist(model.getUsername());
    }

    @PostMapping("/updateUser")
    @ApiOperation("更新用户信息")
    public BasisResultful<Object> updateUser(@RequestBody @Validated SysUserInfoModel model) {
        return sysUserInfoService.updateUser(model);
    }

    @PostMapping("/deleteUser")
    @ApiOperation("删除用户信息")
    public BasisResultful<Object> deleteUser(@RequestBody @Validated SysUserInfoModel model) {
        return sysUserInfoService.deleteUser(model.getUserId());
    }

    @PostMapping("/addUser")
    @ApiOperation("新增用户信息")
    public BasisResultful<Object> addUser(@RequestBody @Validated SysUserInfoModel model) {
        return sysUserInfoService.addUser(model);
    }

    @PostMapping("/setUserStatus")
    @ApiOperation("设置用户状态")
    public BasisResultful<Object> setUserStatus(@RequestBody @Validated SysUserInfoModel model) {
        return sysUserInfoService.setUserStatus(model.getUserId(), model.getStatus());
    }


}
